package com.yanchangapp.ui.presenter;

import com.yanchangapp.base.HeadApiRetrofit;
import com.yanchangapp.commom.AppConstant;
import com.yanchangapp.model.response.ClauseEditResponse;
import com.yanchangapp.ui.view.ClauseEditAtView;
import com.zxl.baselib.ui.base.BaseActivity;
import com.zxl.baselib.ui.base.BaseObserver;
import com.zxl.baselib.ui.base.BasePresenter;
import com.zxl.baselib.ui.base.ExceptionHandle;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;

/**
 * Created by apple on 2019-08-20.
 * description: 合同条款编辑的p层
 */
public class ClauseEditAtPresenter extends BasePresenter<ClauseEditAtView> {

    public ClauseEditAtPresenter(BaseActivity context) {
        super(context);
    }

    public void getDefaultClause(){
        HeadApiRetrofit.getInstance().queryDefaultClause()
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new BaseObserver<ClauseEditResponse>() {
                    @Override
                    public void onNext(ClauseEditResponse clauseEditResponse) {
                        if (null != getView()){
                            if (clauseEditResponse.getCode() == AppConstant.REQUEST_SUCCESS){
                                getView().getDefaultClauseSuccess(clauseEditResponse.getData());
                            }else {
                                getView().getDefaultClauseFailure(clauseEditResponse.getMsg());
                            }
                        }
                    }

                    @Override
                    public void onError(ExceptionHandle.ResponseException exception) {
                        if (null != getView()){
                            getView().getDefaultClauseFailure(exception.getErrorInfo());
                        }
                    }
                });
    }
}
